package com.mycompany.app.hr.tna.service.impl;

import java.util.Calendar;
import java.util.Date;

import com.mycompany.app.hr.tna.service.ICalendarService;

public class CalendarServiceImpl implements ICalendarService {
    
    private Calendar calendar=Calendar.getInstance();

    public synchronized int getYear(Date date) {
        calendar.setTime(date);
        return calendar.get(Calendar.YEAR);
    }
    
    public synchronized int getMonth(Date date) {
        calendar.setTime(date);
        return calendar.get(Calendar.MONDAY);
    }

    public synchronized int getDayOfWeek(Date date) {

        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

    public boolean isCalendarRestday(Date date) {

        // TODO Auto-generated method stub
        // return false;
        return getDayOfWeek(date) > 5 ? true : false;
    }

    public static void main(String[] args) {
 
        ICalendarService testCalendarServiceImpl = new CalendarServiceImpl();
        Date testDate = new Date();
        int year = testCalendarServiceImpl.getYear(testDate);
        System.out.println(year);
        int dayOfWeek = testCalendarServiceImpl.getDayOfWeek(testDate);
        System.out.println(dayOfWeek);
        boolean restday = testCalendarServiceImpl.isCalendarRestday(testDate);
        System.out.println(restday);
        
        System.out.println(testCalendarServiceImpl.getMonth(new Date()));

    }



}
